extends Node

@export var sprite: Sprite2D
@export var health_component: HealthComponent
@export var hit_flash_componnt_material: ShaderMaterial
var flash_tween: Tween

func _ready() -> void:
	health_component.health_changed.connect(on_health_changed)
	sprite.material = hit_flash_componnt_material
	
func on_health_changed():
	if flash_tween != null && flash_tween.is_valid():
		flash_tween.kill()
	flash_tween = create_tween()
	(sprite.material as ShaderMaterial).set_shader_parameter("flashnumber", 1.0)
	flash_tween.tween_property(sprite.material, "shader_parameter/flashnumber", 0, 0.3)
	
